package com.wanghua.mall.product.webcontroller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanghua.mall.product.entity.CategoryEntity;
import com.wanghua.mall.product.frontvo.Catalog2Vo;
import com.wanghua.mall.product.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author wanghua
 * @create 2021-08-27 12:32
 */
@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @GetMapping({"/", "/index"})
    public String indexPage(Model model) {
        List<CategoryEntity> oneCategoryEntityList = categoryService.list(new QueryWrapper<CategoryEntity>().eq("level", 1));
        model.addAttribute("oneCategoryEntityList", oneCategoryEntityList);
        return "index";
    }

    /**
     * 前台使用
     * @return
     */
    @ResponseBody
    @GetMapping("index/catalog.json")
    public Map<String, List<Catalog2Vo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }
}
